package com.codec;

import com.alibaba.fastjson.JSON;
import com.entity.MsgData;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import org.springframework.util.StringUtils;

import java.nio.charset.Charset;
import java.util.List;

/**
 * @program: mpf-eventbridge
 * @description:
 * @author: zt22328 赵儒定
 * @create: 2022-11-30 09:44
 **/
public class AppConfigDecoder extends MessageToMessageDecoder<ByteBuf> {

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> out) throws Exception {
        String body = byteBuf.toString(Charset.defaultCharset());
        if(StringUtils.isEmpty(body)){
            return;
        }
        out.add(JSON.parseObject(body, MsgData.class));
    }
}
